<template>
	<view>
		<view class="top_box"> </view>
		<view class="avatar_content">
			<view class="avatar_box">
				<image src="https://res.huibiaow.cn/file/20250703/17515376253221.png" class="avatar_img"
					v-if="!hasLogin"></image>
				<image :src="'https://www.zhenbiaow.com'+ userInfo.avatar " class="avatar_img" v-if="hasLogin"></image>
			</view>
			<view class="loginBox">
				<view class="notLoggedIn" @click="loginNow()" v-if="!hasLogin">立即登录</view>
				<view class="name_text" v-if="hasLogin">{{userInfo.username}}</view>
			</view>
			<view class="menu_box">
				<view class="item_box" @click='clickPhone("13545810260")'>
					<view class="item_left">
						<image src="https://res.huibiaow.cn/file/20250630/17512765092881.png" class="left_icon"></image>
						<view class="text">联系客服</view>
					</view>
					<view class="item_right">
						<view class="text">13545810260</view>
						<image src="https://res.huibiaow.cn/xcx_cyolw/user/rigaht_icon.png" class="right_icon">
						</image>
					</view>
				</view>
				<view class="item_box" @click="expertConsultation()">
					<view class="item_left">
						<image src="https://res.huibiaow.cn/file/20250630/17512765092077.png" class="left_icon"></image>
						<view class="text">微信客服</view>
					</view>
					<view class="item_right">
						<image src="https://res.huibiaow.cn/xcx_cyolw/user/rigaht_icon.png" class="right_icon">
						</image>
					</view>
				</view>
			</view>
			<view class="menu_box has_top" v-if="hasLogin&&userInfo.is_admin=='1'" @click='ToCar()'>
				<view class="item_box">
					<view class="item_left">
						<image src="https://res.huibiaow.cn/file/20250630/17512765091742.png" class="left_icon"></image>
						<view class="text">分享名片</view>
					</view>
					<view class="item_right">
						<image src="https://res.huibiaow.cn/xcx_cyolw/user/rigaht_icon.png" class="right_icon">
						</image>
					</view>
				</view>
			</view>
			<view class="yz_box" @click="ToTj()">
				<img src="https://res.huibiaow.cn/file/20250630/17512786386646.png" alt="">
			</view>
			<view class="btns" v-if="hasLogin">
				<view class="btn logout" @click="doLogout()">退出登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import config from '@/config.js';
	export default {
		data() {
			return {
				configData: "",
			}
		},
		onShow() {
			this.configData = config.new_applet_info;
			if (this.hasLogin) {
				this.setUserInfo();
			}
			console.log(this.userInfo)
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'token'])
		},
		methods: {
			...mapMutations(['login', 'setUserInfo', 'logout']),
			// 退出登录
			doLogout() {
				const that = this;
				uni.showModal({
					title: '提示',
					content: '确定退出当前账号吗？',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '请稍候...'
							});
							that.$request({
								url: 'index/index/logout_wx',
								success: (res) => {
									uni.hideLoading();
									if (res.code == 0) {
										that.logout()
										uni.showToast({
											title: '账号已退出'
										})
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none'
										});
									}
								}
							});
						}
					}
				})
			},

			loginNow() {
				// if (!this.hasLogin) {
				uni.navigateTo({
					url: '/subMyPage/login/login'
				});
				// }
			},
			// 拨打用户电话
			clickPhone(phone) {
				if (phone) {
					uni.makePhoneCall({
						phoneNumber: phone
					});
				} else {
					uni.showToast({
						title: "用户暂无手机号",
						mask: true,
						icon: 'none'
					})
				}
			},
			//跳转到微信客服
			expertConsultation() {
				let _this = this;
				wx.openCustomerServiceChat({
					extInfo: {
						url: 'https://work.weixin.qq.com/kfid/kfcf6d12abc1bc978ac'
					},
					corpId: 'ww5dd97fa44d21426f',
					success(res) {
						console.log('成功打开客服聊天界面');
					},
					fail(err) {
						console.log('打开客服聊天界面失败', err);
					}
				})
			},
			// 跳转到我的名片
			ToCar() {
				uni.navigateTo({
					url: '/subMyPage/BusinessCard/BusinessCard'
				})
			},
			// 跳转商标推荐
			ToTj() {
				uni.navigateTo({
					url: '/subMyPage/HotClass/HotClass'
				})
			}
		}
	}
</script>

<style lang='scss'>
	page {
		background: linear-gradient(0deg, #FCFDFF 0%, #F5F8FE 100%);
	}

	.top_box {
		height: 410rpx;
		background: linear-gradient(138deg, #F0F6FF 0%, #C1DAFF 100%);
	}

	.avatar_content {
		/* height: 410rpx; */
		background: linear-gradient(0deg, #FCFDFF 0%, #F5F8FE 100%);
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		margin-top: -50rpx;

		.avatar_box {
			position: relative;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			flex-wrap: wrap;
			height: 80rpx;

			.avatar_img {
				position: absolute;
				top: -80rpx;
				z-index: 10;
				border-radius: 30rpx 30rpx 0rpx 0rpx;
				border: 2px solid #FFFFFF;
				border-radius: 50%;
				width: 160rpx;
				height: 160rpx;
			}
		}

		.loginBox {
			display: flex;
			flex-direction: row-reverse;
			justify-content: center;
			align-items: center;
			flex-wrap: wrap;

			.notLoggedIn {
				margin-top: 25rpx;
				margin-bottom: 31rpx;
				width: 200rpx;
				height: 60rpx;
				border-radius: 30rpx;
				border: 1px solid #295094;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #295094;
				line-height: 60rpx;
				text-align: center;
			}

			.name_text {
				margin-top: 36rpx;
				margin-bottom: 46rpx;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #333333;
				text-align: center;
			}
		}

		.menu_box {
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0rpx 25rpx;
			margin: 0rpx 30rpx;

			&.has_top {
				margin-top: 20rpx;
			}

			.item_box {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				flex-wrap: wrap;
				padding: 28rpx 0rpx;
				border-bottom: 2rpx solid #F4F4F4;
				margin: 0rpx 28rpx;

				.item_left {
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: center;
					flex-wrap: wrap;

					.left_icon {
						width: 36rpx;
						height: 36rpx;
					}

					.text {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #333333;
						margin-left: 22rpx;
					}
				}

				.item_right {
					display: flex;
					flex-direction: row;
					justify-content: flex-end;
					align-items: center;
					flex-wrap: wrap;

					.text {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #999999;
						margin-right: 26rpx;
					}

					.right_icon {
						width: 14rpx;
						height: 26rpx;
					}
				}
			}

			.item_box:last-child {
				border-bottom: 0rpx solid #F4F4F4;
			}
		}

		.yz_box {
			margin: 30rpx 30rpx 0;
			box-sizing: border-box;

			img {
				width: 100%;
				max-height: 120rpx;
			}
		}

		.btns {
			display: flex;
			margin: 30upx 0upx;
			position: absolute;
			width: 100%;
			bottom: 0rpx;

			.btn {
				height: 90rpx;
				line-height: 80upx;
				text-align: center;
				flex: 1;
				margin: 0 24upx;
			}

			.logout {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #445061;
				background: #F0F2F4;
				border-radius: 20rpx;
				border: 1px solid #FFFFFF;
			}

			.restart {
				color: #333333;
				background: #eae8e8;
			}
		}
	}
</style>